def eratosthenes(limit):
    # Sieve of Eratosthenes has a complexity of:
    # O(n)
    # Memory requirement
    # O(n^1/2 loglogn / logn)
    sievearr = []
    primenumbers = []
    # Assuming limit = 10
    for i in range(limit)[2:]: # Due to the [2:] it will generate a list -> [2, 3, 4, 5, 6, 7, 8, 9]
        sievearr.append(i) # Put all the numbers into an array
    for i in sievearr: # Loop through all the numbers
        if i == 0: # If i == 0 then skip it
            continue
        pos = sievearr.index(i) # This is used as an offset because the number in the list doesn't correspond to the actual location in the array (ie the first element
                                # would be 0, but the first value is 2
        steparr = range(i, limit-2, i) # Generate a list between the current number and limit - 2 with a step of the current number (assuming it was 2) -> [2, 4, 6]
                                       # Note: It may appear these will be the numbers to be taken off the list, however, the "pos" will be an offset, which at 2 will be
                                       # 0 so the numbers at the 2nd position (2) 4th position (6) and the 6th position (8)
        for x in steparr: # -> [2, 4, 6]
            if (pos + x) < len(sievearr): # If the offset + number < the length of the sieve array, we need this test so we don't reach into elements that don't exist
                sievearr[pos+x] = 0 # Set it to 0
            else:
                break # break causes the loop to stop immediatly and continue execution with the rest of the code (ie the execution of the previous loop
    for i in sievearr:
        if i != 0:
            primenumbers.append(i) # Filter out all the remaining numbers into a new array
    
    print primenumbers[len(primenumbers)-1] # Print out the highest prime number
    return
eratosthenes(99999)